//
// Created by YE on 2024/1/5.
//
#include "interpreter.h"


//void Interpreter::handle_error(handle_error_function e_f, Error_State state, void *data) {
//    e_f(state,data);
//}
Interpreter::Interpreter() = default;

Interpreter_State Interpreter::reader_init(const char *file_path) {
    reader = new Reader();
    return reader->read_file(file_path);
}

Interpreter::~Interpreter() {
    delete parser, lexer, reader, executor;
}

Interpreter_State Interpreter::lexer_init() {
    lexer = new Lexer(reader);
    return lexer ? YCH_OK : YCH_NO;
}

Interpreter_State Interpreter::parser_init() {
    parser = new Parser(lexer);
    return parser ? YCH_OK : YCH_NO;
}

Interpreter_State Interpreter::compiler(const char *file_path) {
    if (!reader_init(file_path)) return YCH_NO;
    if (!lexer_init()) return YCH_NO;
    if (!parser_init())return YCH_NO;
    parser->load_CLib();
    Parser_State s = parser->parse();
    while (s == PARSER_OK)s = parser->parse();
    return YCH_OK;
}



